package com.wish.business.controller;


import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.wish.business.entity.SysRegion;
import com.wish.business.service.ISysRegionService;
import com.wish.common.core.usconfig.common.MsgResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 杨子强-地区表 前端控制器
 * </p>
 *
 * @author benjamin
 * @since 2022-03-26
 */
@RestController
@RequestMapping("/sys-region")
public class SysRegionController {

    @Autowired
    ISysRegionService iSysRegionService;

    @GetMapping("/regionList")
    public MsgResult regionList() {
        List<SysRegion> list = iSysRegionService.list();
        List<Tree<Integer>> build = TreeUtil.build(list, 1,
                (region, tree) -> {
                    tree.setId(region.getRegionId());
                    tree.setName(region.getRegionName());
                    tree.setParentId(region.getParentId());
                });
        System.out.println(build);
        return MsgResult.succeed(build);
    }

}
